package main

import (
	"log/slog"
	"os"
	"os/signal"
	"statsphere/pkg/cache"
	"statsphere/pkg/emqx"
	"statsphere/pkg/gwprop"
	"statsphere/pkg/log"
	"statsphere/util"
	"syscall"
)

func main() {
	interrupt := make(chan os.Signal, 2)
	signal.Notify(interrupt, syscall.SIGINT, syscall.SIGTERM)

	work()

	// 订阅 系统程序的 退出
	for {
		select {
		case tmp, _ := <-interrupt:
			// 释放 redis 等
			slog.Error("程序关闭", "interrupt", tmp)
			util.CloseBolt()
			util.CloseRedis()
			os.Exit(0)
		}
	}
}

func work() {
	log.Setup()
	gwprop.SetUp()
	cache.SetUp()
	emqx.Setup()
	// 加载 redis
	util.SubscribeRedis()
}
